﻿using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2025-07-02
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 报警记录
    /// </summary>
    [Verify]
    [Route("business/CksAlarmRecord")]
    [ApiExplorerSettings(GroupName = "business")]
    public class CksAlarmRecordController : BaseController
    {
        /// <summary>
        /// 报警记录接口
        /// </summary>
        private readonly ICksAlarmRecordService _CksAlarmRecordService;

        public CksAlarmRecordController(ICksAlarmRecordService CksAlarmRecordService)
        {
            _CksAlarmRecordService = CksAlarmRecordService;
        }

        /// <summary>
        /// 查询报警记录列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "cksalarmrecord:list")]
        public IActionResult QueryCksAlarmRecord([FromQuery] CksAlarmRecordQueryDto parm)
        {
            var response = _CksAlarmRecordService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询报警记录详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "cksalarmrecord:query")]
        public IActionResult GetCksAlarmRecord(long Id)
        {
            var response = _CksAlarmRecordService.GetInfo(Id);

            var info = response.Adapt<CksAlarmRecordDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加报警记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "cksalarmrecord:add")]
        [Log(Title = "报警记录", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCksAlarmRecord([FromBody] CksAlarmRecordDto parm)
        {
            var modal = parm.Adapt<CksAlarmRecord>().ToCreate(HttpContext);

            var response = _CksAlarmRecordService.AddCksAlarmRecord(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新报警记录
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "cksalarmrecord:edit")]
        [Log(Title = "报警记录", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCksAlarmRecord([FromBody] CksAlarmRecordDto parm)
        {
            var modal = parm.Adapt<CksAlarmRecord>().ToUpdate(HttpContext);
            var response = _CksAlarmRecordService.UpdateCksAlarmRecord(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除报警记录
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "cksalarmrecord:delete")]
        [Log(Title = "报警记录", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCksAlarmRecord([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_CksAlarmRecordService.Delete(idArr));
        }

    }
}